home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / Compatibility.java < prev    next >
Text File  |  1998-09-15  |  2KB  |  77 lines

  1. package alternative;
  2.  
  3. import java.applet.*;
  4. import java.awt.*;
  5.  
  6. public class Compatibility extends Applet {
  7.     /* Should localize the following. */
  8.     protected String labelText = "Your browser can't run 1.1 applets.";
  9.     protected String filename;   // value to be provided by a subclass
  10.     PictureFrame frame;
  11.  
  12.     public void init() {
  13.     setLayout(new BorderLayout());
  14.  
  15.     Button button = new Button("Click here!");
  16.     add("Center", button);
  17.  
  18.     Label label = new Label(labelText);
  19.     label.setForeground(Color.red);
  20.     add("North", label);
  21.  
  22.     System.out.println("Image filename is " + filename);
  23.  
  24.     if (filename == null) {
  25.         label.disable();
  26.         button.disable();
  27.         return;
  28.     } 
  29.     //needed because this is running under Switcher
  30.     Applet parentApplet;
  31.     
  32.     /* Get the parent Applet object. */
  33.     try {
  34.       parentApplet = (Applet)getParent();
  35.     } catch (ClassCastException e) {
  36.       System.err.println("Parent isn't an Applet!");
  37.       throw(e);
  38.     }
  39.         
  40.     Image image = parentApplet.getImage(parentApplet.getCodeBase(), filename);
  41.     String gifWidth = parentApplet.getParameter("GIFWIDTH");
  42.     String gifHeight = parentApplet.getParameter("GIFHEIGHT");
  43.     int w = 200;
  44.     int h = 200;
  45.  
  46.     if (gifWidth != null) {
  47.         try {
  48.         w = Integer.parseInt(gifWidth);
  49.         } catch (NumberFormatException e) {
  50.         //Use default width.
  51.         }
  52.     }
  53.  
  54.     if (gifHeight != null) {
  55.         try {
  56.         h = Integer.parseInt(gifHeight);
  57.         } catch (NumberFormatException e) {
  58.         //Use default height.
  59.         }
  60.     }
  61.  
  62.     frame = new PictureFrame(image, w, h);
  63.     }
  64.  
  65.     public void stop() {
  66.     frame.hide();
  67.     }
  68.  
  69.     public boolean action(Event e, Object arg) {
  70.     if (frame != null) {
  71.         frame.pack();
  72.         frame.show();
  73.     }
  74.     return true;
  75.     }
  76. }
  77.